package com.ruoyi.project.hidden.hiddenName.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.hidden.hiddenName.domain.HiddenName;
import com.ruoyi.project.hidden.hiddenName.service.IHiddenNameService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 风险名称Controller
 * 
 * @author ruoyi
 * @date 2021-01-23
 */
@Controller
@RequestMapping("/hidden/hiddenName")
public class HiddenNameController extends BaseController
{
    private String prefix = "hidden/hiddenName";

    @Autowired
    private IHiddenNameService hiddenNameService;

    @RequiresPermissions("hidden:hiddenName:view")
    @GetMapping()
    public String hiddenName()
    {
        return prefix + "/hiddenName";
    }

    /**
     * 查询风险名称列表
     */
    @RequiresPermissions("hidden:hiddenName:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(HiddenName hiddenName)
    {
        startPage();
        List<HiddenName> list = hiddenNameService.selectHiddenNameList(hiddenName);
        return getDataTable(list);
    }

    /**
     * 导出风险名称列表
     */
    @RequiresPermissions("hidden:hiddenName:export")
    @Log(title = "风险名称", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(HiddenName hiddenName)
    {
        List<HiddenName> list = hiddenNameService.selectHiddenNameList(hiddenName);
        ExcelUtil<HiddenName> util = new ExcelUtil<HiddenName>(HiddenName.class);
        return util.exportExcel(list, "hiddenName");
    }

    /**
     * 新增风险名称
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存风险名称
     */
    @RequiresPermissions("hidden:hiddenName:add")
    @Log(title = "风险名称", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(HiddenName hiddenName)
    {
        return toAjax(hiddenNameService.insertHiddenName(hiddenName));
    }

    /**
     * 修改风险名称
     */
    @GetMapping("/edit/{riskId}")
    public String edit(@PathVariable("riskId") Long riskId, ModelMap mmap)
    {
        HiddenName hiddenName = hiddenNameService.selectHiddenNameById(riskId);
        mmap.put("hiddenName", hiddenName);
        return prefix + "/edit";
    }

    /**
     * 修改保存风险名称
     */
    @RequiresPermissions("hidden:hiddenName:edit")
    @Log(title = "风险名称", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(HiddenName hiddenName)
    {
        return toAjax(hiddenNameService.updateHiddenName(hiddenName));
    }

    /**
     * 删除风险名称
     */
    @RequiresPermissions("hidden:hiddenName:remove")
    @Log(title = "风险名称", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(hiddenNameService.deleteHiddenNameByIds(ids));
    }
}
